package com.cs2340.taskplusplus;

import java.util.ArrayList;
import java.util.Date;

import android.test.AndroidTestCase;


/**
 * A JUnit test for testing the expansion procedure, comprising the 
 * Task.expand() method and one of the TaskList constructors.
 * @author Charles of GRILLENBANNER
 *
 */
public class JUnitCharles extends AndroidTestCase 
{

	Account a;
	
	public void testSomething() throws Throwable
	{
		
    	a = new Account("default");
    	a.deleteAccount("test");
    	a = new Account("test","test","test","test");
		TaskList t = a.getMasterList();
		
		//add stuff
		t.addTask(new Task(null,"Task 1", "Task 1", new Date(), null, new Location(0,0)));
		t.addTask(new Task(null,"Task 2", "Task 2", new Date(), null, new Location(0,0)));
		t.addTask(new Task(null,"Task 3", "Task 3", new Date(), null, new Location(0,0)));
		
		
		
		//check they're all Tasks, and expand one.
		int i = 0;
	    TaskList sub = null;
	    t.expand("Task 1");
		
		//check that one is now a TaskList
		i = 0;
		for (Doable d : t.getList() )
		{
			if (d.isList())
			{
				sub = (TaskList) d;
				i++;
			}
		}
		assertTrue(i==1);
		
		//check that you can add to the new TaskList
		i = 0;
		sub.addTask(new Task(null,"subTask 1", "subTask 1", new Date(), null, new Location(0,0)));
		assertTrue(sub.getList().size() == 1);
		
		//check that the original list and sub's parent are the same.
		TaskList subpar = new TaskList(sub.getParentTable());
		
		ArrayList<Doable> subparlist = subpar.getList();
		ArrayList<Doable> tlist = t.getList();
		System.out.println(subparlist.size()+" "+tlist.size());
		assertTrue(subparlist.size() == tlist.size());
		//via checking their content's names
		for (int j = 0; j<tlist.size(); j++)
		{
			assertTrue(subparlist.get(j).getName().equals(tlist.get(j).getName()));
		}
		
		
	}
	
	
}
